package com.societyGames.flashForms
{
import flash.display.Sprite;
import flash.events.MouseEvent;

public class FourStateButton extends ThreeStateButton
{
  private var _enabled:Boolean = true;
  private var _inactive:Sprite;

  public function FourStateButton(inactive:Sprite, up:Sprite, over:Sprite = null, down:Sprite = null)
  {
    super(up, over, down);
    this._inactive = inactive;
  }

  public function get enabled():Boolean
  {
    return this._enabled;
  }

  public function set enabled(value:Boolean):void
  {
    if (value != this._enabled)
    {
      this._enabled = value;
      this.mouseEnabled = this._enabled;
      if (this._enabled)
      {
        if (this.stage != null && this.hitTestPoint(this.stage.mouseX, this.stage.mouseY))
        {
          setSprite(this._over);
        }
        else
        {
          setSprite(this._up);
        }
      }
      else
      {
        setSprite(this._inactive);
      }
    }
  }

  protected override function internalClickHandler(event:MouseEvent):void
  {
    if (this._enabled)
    {
      this._buttonClickEventObject.dispatchEvent();
    }
  }

  protected override function setSprite(sprite:Sprite):void
  {
    if (this._enabled)
    {
      super.setSprite(sprite);
    }
    else
    {
      super.setSprite(this._inactive);
    }
  }

  public override function set height(value:Number):void
  {
    super.height = value;
    this._inactive.height = value;
  }

  public override function set width(value:Number):void
  {
    super.width = value;
    this._inactive.width = value;
  }
}
}